#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
using namespace std;
int main()
{string data[100];
string findstr[] = {"DATE", "CCBQ", "PNP", "G3P"};
int find[4];
ifstream infile("c:\\scada.txt");
ofstream outfile("scadaording.txt");
int k = 0;
int i = 0;
int j = 0;
for (i = 0;i < 100;i ++) {getline(infile, data[i], '\n');
}string str1 = data[0];
for (i = 0;i <4;i ++) {int findindex = str1.find(findstr[i], 0);
int startindex = 0;
int endindex = 0;
int count = 0;
while( (( endindex = str1.find ( ",", startindex )) > 0)&(endindex <findindex) )
{count++;\
startindex = endindex + 1;
}find[i]=count+1;
}string la[100];
string lb[100];
string lc[100];
string ld[100];
double sum_ccbp = 0;
double sum_pnp = 0;
double sum_g3p = 0;
for(i = 0;i < 100;i ++) {string str = data[i];
int startindex = 0;
int endindex = 0;
int cnt = 0;
while( (endindex = str.find(",", startindex)) > 0 )
{cnt++;
if (cnt == find[0])
{la[i]= str.substr(startindex, endindex - startindex);
} else if (cnt == find[1])
{lb[i]= str.substr(startindex, endindex - startindex);
} else if (cnt == find[2])
{lc[i]= str.substr(startindex, endindex - startindex);
} else if (cnt == find[3])
{ld[i]= str.substr(startindex, endindex - startindex);
}startindex = endindex + 1;
}outfile << la[i] << ' '<< lb[i] << ' '<< lc[i] << ' '<< ld[i] << ' ' << endl;
sum_ccbp+=atof(lb[i].c_str());
sum_pnp+=atof(lc[i].c_str());
sum_g3p+=atof(ld[i].c_str());
}printf("averageCCBPd=%.15f\taverageCCBPf=%.15f\n",
        sum_ccbp/96, float(sum_ccbp/96));
printf("averagePNPd=%.15f\taveragePNPf=%.15f\n",
       sum_pnp/96, float(sum_pnp/96));
printf("averageG3Pd=%.15f\taverageG3Pf=%.15f\n",
       sum_g3p/96, float(sum_g3p/96));
return 0;
}


